﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OracleClient;
using BCNPCObject.DB;
using DbLinq;
using DbLinq.Oracle;
using CMISLibrary.Entities;
using CMISLibrary;
namespace BCNPCObject.EXCEL
{
    public class cls_HDG_BBAN_APGIA_Controller
    {
         #region   Atributes

        //private DataSet CMIS_Header = new CMISOutputParameter();
        private HDG_BBAN_APGIA info;

        #endregion

        #region   Constructor

        public cls_HDG_BBAN_APGIA_Controller()
        {
            info = new HDG_BBAN_APGIA();
        }
        public cls_HDG_BBAN_APGIA_Controller(HDG_BBAN_APGIA Info)
        {
            this.info = Info;
        }

        #endregion

        #region   Properties

        public HDG_BBAN_APGIA pInfor
        {
            get { return info; }
            set { info = value; }
        }
        #endregion

        #region Methods
        public bool insert_HDG_BBAN_APGIA(ref Int64 id_bbanagia,ref string maloi)
        {
            long _ID = CMIS2.DB.ExecuteCommand("Select SEQ_HDG_BBAN_APGIA.NEXTVAL from dual");
            if (_ID == -1) return false;
            try
            {
                info.ID_BBANAGIA = Convert.ToInt64(_ID);
                HDG_BBAN_APGIA objHDG_BBAN_APGIA = new HDG_BBAN_APGIA()
                {
                    MA_DVIQLY = info.MA_DVIQLY,
                    MA_DDO = info.MA_DDO,
                    ID_BBANAGIA = info.ID_BBANAGIA,
                    MA_BBANAGIA = info.MA_BBANAGIA,
                    SO_THUTU = info.SO_THUTU,
                    DINH_MUC = info.DINH_MUC,
                    LOAI_DMUC = info.LOAI_DMUC,
                    LOAI_BCS = info.LOAI_BCS,
                    TGIAN_BDIEN = info.TGIAN_BDIEN,
                    MA_NGIA = info.MA_NGIA,
                    MA_NHOMNN = info.MA_NHOMNN,
                    MA_NN = info.MA_NN,
                    TRANG_THAI = info.TRANG_THAI,
                    SO_HO = info.SO_HO,
                    MA_CAPDAP = info.MA_CAPDAP,
                    DIEN_GIAI = info.DIEN_GIAI,
                    NGAY_HLUC = info.NGAY_HLUC,
                    MA_CNANG = info.MA_CNANG,
                    NGAY_TAO = info.NGAY_TAO,
                    NGUOI_TAO = info.NGUOI_TAO,
                    NGAY_SUA = info.NGAY_SUA,
                    NGUOI_SUA = info.NGUOI_SUA
                };
                CMIS2.DB.HDG_BBAN_APGIA.InsertOnSubmit(info);
                CMIS2.DB.SubmitChanges();
                id_bbanagia = _ID;
                CMIS2.ResetDB();
                return true;
            }
            catch (Exception ex)
            {
                maloi = ex.ToString();
                CMIS2.ResetDB();
                return false;
            }
        }
        public bool delete_HDG_BBAN_APGIA(DataTable dt, ref string maloi)
        {
            try
            {
                if (dt != null && dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Columns.Count; i++)
                    {
                        var query = from p in CMIS2.DB.HDG_BBAN_APGIA
                                    where (p.MA_DVIQLY == dt.Rows[i]["MA_DVIQLY"].ToString() && p.MA_DDO == dt.Rows[i]["MA_DDO"].ToString() && p.NGAY_HLUC == Convert.ToDateTime(dt.Rows[i]["NGAY_HLUC"]) && p.ID_BBANAGIA == Convert.ToInt64(dt.Rows[i]["ID_BBANAGIA"]))
                                    select p;
                        if (query != null && query.Count() > 0)
                        {
                            CMIS2.DB.HDG_BBAN_APGIA.DeleteAllOnSubmit(query.ToList());
                            CMIS2.DB.SubmitChanges();
                        }
                    }
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                maloi = ex.ToString();
                CMIS2.ResetDB(); return false;
            }
        }
        #endregion
    }
}
